﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OCDStudio.SqlAzureBackup.Client.Properties;

namespace OCDStudio.SqlAzureBackup.Client.Code
{
    public class ProfileManager
    {
        private static List<BackupProfile> profiles;

        public static List<BackupProfile> Profiles
        {
            get
            {
                if (profiles == null)
                {
                    StringProfiles = Settings.Default.Profiles;
                } return ProfileManager.profiles;
            }
            set { 
                ProfileManager.profiles = value==null?new List<BackupProfile>():value;
                Settings.Default.Profiles = StringProfiles;
                Settings.Default.Save();
            }
        }

        public static string StringProfiles {
            get { return Profiles.AsXmlString(); }
            set
            {
                Profiles = value.AsObjectFromXml<List<BackupProfile>>();
            }
         }

        public static void AddProfile(BackupProfile prof)
        {
            Profiles.Add(prof);
            Profiles = Profiles;
        }


        public static void RemoveProfile(BackupProfile prof)
        {
            Profiles.Remove(prof);
            Profiles = Profiles;
        }
    }
}
